<?Php

    
    require_once '../Resources/libs/SmartyPaginate/libs/SmartyPaginate.class.php';
    include '../ConfigSite/Smarty/ConfigSmarty.php';
    include '../ConfigSite/DataBase/DB_Conexion.php';
    include 'Model/mld_Cursos.php';
    $smarty = new ConfigSmarty();
    $time = time() - $_SESSION["NowTime"];

    if ($_SESSION["Usuario"] !== null and $time <= 600) {
            SmartyPaginate::reset();
            $_SESSION["NowTime"] = time();
            $smarty-> plugins_dir= '../Resources/libs/SmartyPaginate/plugins';
            SmartyPaginate :: connect();
            SmartyPaginate :: setLimit(4);

            $smarty->assign("resultados", get_db_results());
            SmartyPaginate ::assign($smarty);
            
            $smarty->setDirectorio('Cursos');
            $smarty->display('asignarCursoProfesor.tpl');

    }  else {
            header("Location: ../../Login");
    }
    
    
    

function get_db_results () {
    $conn = new DB_Conexion(1);
    $model = new mld_Cursos($conn->db);
    if (isset($_POST['BuscarCurso']) ) {
        $resul = $model->MostrarCurso($_POST['BuscarCurso']);
    }  else {
        $resul = $model->MostrarCurso("");
    }
    
    SmartyPaginate :: setTotal(count($resul));
    return array_slice($resul, SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
}
echo 'fin';
?>